﻿using Gengens.Disk.Entity.entity.file;
using Gengens.Disk.Repository.repository;

namespace Gengens.Disk.Service.service
{
    public class DataInfoService : BaseService<DataInfo>
    {
        public DataInfoService(DataInfoRepository repository) : base(repository)
        {
        }

        public override void Delete(DataInfo model)
        {
            var refer = Select(m => m.Url == model.Url && m.Id != model.Id);
            if (refer == null || refer.Count == 0)
            {
                //删除静态资源
                if (File.Exists(model.Url)) File.Delete(model.Url);
            }
            base.Delete(model);
        }

        public override void DeleteRange(List<DataInfo> models)
        {
            foreach (var item in models)
            {
                Delete(item);
            }
        }
    }
}
